package com.yoome.easyrpc.biz.loadbalance;

import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.List;

public abstract class AbstractLoadBalance implements LoadBalance {

    public String selectService(List<String> services, String serviceName) {
        if (CollectionUtils.isEmpty(services)) {
            return null;
        }

        if (services.size() == 1) {
            return services.get(0);
        }

        return select(services, serviceName);
    }

    protected abstract String select(List<String> services, String serviceName);
}
